// 分配土地: 全遍历, 记录非0数字的点, 进行收集; 再次遍历, 统计每个数字的面积, 取最小的那个
//3 3
//1 0 1
//0 0 0
//0 1 0
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let m, n; // m列, n行
let initArr = [];
rl.on("line", (line) => {
    if (m === undefined) {
        [m, n] = line.trim().split(" ").map(Number)
    } else {
        initArr.push(line.trim().split(" ").map(Number))
        if(initArr.length === m) {
            console.log(getResult(m, n, initArr))

            // clear
            m = n = undefined
            initArr.length = 0
        }

    }
})

function getResult(m, n, initArr) {
    let obj = {}
    for (let i = 0; i < m ; i++) {
        for (let j = 0; j <n ; j++) {
            let num = initArr[i][j]
            if(num !== 0) {
                if(!obj[num]) {
                    obj[num] = []
                }
                obj[num].push([i, j])
            }
        }
    }

    // 开始统计
    let count = Infinity
    for (const arr of Object.values(obj)) {
        if(arr.length === 1) {
            count = 1;
            break
        }
        let l = arr[0][1]
        let r = arr[0][1]
        let t = arr[0][0]
        let b = arr[0][0]
        for (const childArr of arr) {
            const [x, y] = childArr;
            l = Math.min(l, x)
            r = Math.max(r, x)
            t = Math.min(t, y)
            b = Math.max(b, y)
        }
        let temp = Math.abs(r - l + 1) * Math.abs(b - t + 1)
        count = Math.min(temp, count)
    }
    return count;




}